package com.neusoft.controller;

//根据子项目不同而不同
import com.neusoft.po.BVirtualWallet;
import com.neusoft.service.BVirtualWalletService;

//统一向前端返回的类型，可以统一
import com.neusoft.po.CommonResult;

//其他import,可以统一
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.neusoft.po.CommonResult;

import java.math.BigDecimal;

@RefreshScope //开启动态刷新
@RestController
@RequestMapping("/BVirtualWallet")
public class BVirtualWalletController {

    //自动化注入，子项目不同名称不同
    @Autowired
    private BVirtualWalletService bVirtualWalletService;

    //新增加一个钱包
    @PostMapping("/BVirtualWallet/{businessId}")
    public CommonResult<Integer> saveBVirtualWallet(@PathVariable("businessId")Integer businessId){
        int result = bVirtualWalletService.saveBVirtualWallet(businessId);
        return new CommonResult(200,"success",result);
    }

    //通过商家ID查询整个钱包,包括现有金额
    @GetMapping("/GetBVirtualWalletByBusinessId/{businessId}")
    public CommonResult<BVirtualWallet> getBVirtualWalletByBusinessId(@PathVariable("businessId")Integer businessId){
        BVirtualWallet vir = bVirtualWalletService.getBVirtualWalletByBusinessId(businessId);
        CommonResult commonResult = new CommonResult(200,"success",vir);
        return commonResult;
    }

    //根据商家ID给钱包充值
    @PutMapping("/RechargeByBusinessId/{businessId}/{add_balance}")
    public CommonResult<Integer> rechargeByBusinessId(@PathVariable("businessId")Integer businessId,@PathVariable("add_balance") BigDecimal add_balance){
        int result = bVirtualWalletService.rechargeByBusinessId(businessId,add_balance);
        CommonResult commonResult = new CommonResult(200,"success",result);
        return commonResult;
    }

    //跟据商家ID提现
    @PutMapping("/PayoutByBusinessId/{businessId}/{sub_balance}")
    public CommonResult<Integer> payoutByBusinessId(@PathVariable("businessId")Integer businessId,@PathVariable("sub_balance") BigDecimal sub_balance) {
        int result=bVirtualWalletService.payoutByBusinessId(businessId, sub_balance);
        return new CommonResult(200,"success",result);
    }

}
